'use strict';

import React from 'react';
import { Route, IndexRoute } from 'react-router';
import Layout from 'components/layout/index';
import Index from './containers/index/index';
import Home from './containers/home/index';
import Zhekou1 from './containers/zhekou1/index';
import Zhekou1SetItems from './containers/zhekou1_set_items/index';
import Zhekou1EditItems from './containers/zhekou1_edit_items/index';
import Zhekou1Done from './containers/zhekou1_done/index';
import Zhekou1List from './containers/zhekou1_list/index';
import Zhekou1AllInList from './containers/zhekou1_all_in_list/index';
import ZhekouLimitStep1 from './containers/zhekou_limit_step1/index';
import ZhekouLimitStep2 from './containers/zhekou_limit_step2/index';
import ZhekouLimitList from './containers/zhekou_limit_list/index';
import ZhekouLimitEditItems from './containers/zhekou_limit_edit_items/index';
import Mjs1 from './containers/mjs1/index';
import Mjs1SetItems from './containers/mjs1_set_items/index';
import Mjs1List from './containers/mjs1_list/index';
import RingTags from './containers/ring_tags/index';
import RingTagsStep1 from './containers/ring_tags_step1/index';
import RingTagsStep2 from './containers/ring_tags_step2/index';
import RingTagsStep3 from './containers/ring_tags_step3/index';
import RingZhekouList from './containers/ring_zhekou_list/index';
import RingZhekouEditItems from './containers/ring_zhekou_edit_items/index';
import RingRuningLog from './containers/ring_runing_log/index';
import Page2 from './containers/page2/index';
import Page3 from './containers/page3/index';

let pageTitle = document.title;

/**
 * menu 选中态map,其中value为side-menu组件中的itemid
 */
const menuMap = {
  '/home': 'router-home',
  '/zhekou1': 'router-page1',
  '/page2': 'router-page2'
}

const onRouteEnter = (nextState, replace, callback) => {
  callback();
  //根据路由设置菜单选中
  let routePath = nextState.location.pathname;
  window.selectedMenuKey = menuMap[routePath];
};
const onRouteChange = (prevState, nextState, replace, callback) => {
  callback();
  document.title = nextState.routes[1].title || pageTitle;
  
    //根据路由设置菜单选中
  let routePath = nextState.location.pathname;
  window.selectedMenuKey = menuMap[routePath];
};

export default (<Route path="/" component={Layout} onEnter={onRouteEnter} onChange={onRouteChange}>
  <Route path="index" component={Index} title="index" />
  <Route path="home" component={Home} title="index" />
  <Route path="zhekou1" component={Zhekou1} title="限时折扣"/>
  <Route path="zhekou1_set_items" component={Zhekou1SetItems} title="限时折扣_设置商品"/>
  <Route path="zhekou1_edit_items" component={Zhekou1EditItems} title="限时折扣_编辑商品"/>
  <Route path="zhekou1_done" component={Zhekou1Done} title="限时折扣_完成"/>
  <Route path="zhekou1_list" component={Zhekou1List} title="限时折扣_列表"/>
  <Route path="zhekou1_all_in_list" component={Zhekou1AllInList} title="限时折扣_全店参与列表"/>
  <Route path="zhekou_limit_step1" component={ZhekouLimitStep1} title="限购折扣"/>
  <Route path="zhekou_limit_step2" component={ZhekouLimitStep2} title="限购折扣_设置商品"/>
  <Route path="zhekou_limit_list" component={ZhekouLimitList} title="限购折扣_列表"/>
  <Route path="zhekou_limit_edit_items" component={ZhekouLimitEditItems} title="限购折扣_修改商品"/>
  <Route path="mjs1" component={Mjs1} title="满就送折扣"/>
  <Route path="mjs1_set_items" component={Mjs1SetItems} title="满就送折扣_设置活动范围"/>
  <Route path="mjs1_list" component={Mjs1List} title="满就送折扣_活动列表"/>
  <Route path="ring_tags" component={RingTags} title="连环标签"/>
  <Route path="ring_tags_step1" component={RingTagsStep1} title="连环标签_创建标签"/>
  <Route path="ring_tags_step2" component={RingTagsStep2} title="连环标签_创建折扣"/>
  <Route path="ring_tags_step3" component={RingTagsStep3} title="连环标签_选择商品"/>
  <Route path="ring_zhekou_list" component={RingZhekouList} title="连环标签_折扣列表"/>
  <Route path="ring_zhekou_edit_items" component={RingZhekouEditItems} title="连环标签_修改商品"/>
  <Route path="ring_runing_log" component={RingRuningLog} title="连环标签_运行记录"/>
  <Route path="page2" component={Page2} title="page2"/>
  <Route path="page3" component={Page3} title="page3"/>
  <IndexRoute component={Index}/>
  <Route path="*" component={Home}/>
</Route>);
